(ns clj.jtacck.logging
  (:import jvm.jtacck.Util))

(def logger Util/logger)

(defmacro timing-info ; TODO Change logging level
  "Closely equivilent to (do (print mesg) (time expr)) being piped to
  the logger at the INFO level.  Just small formatting differences."
  [mesg expr] ;; Most of the below is copied from the Clojure source...
  `(let [start# (. System (nanoTime))
         ret# ~expr]
     (log/info
      (str ~mesg " "
       "Elapsed time: "
       (/ (double (- (. System (nanoTime)) start#)) 1000000.0) " msecs"))
     ret#))

(defn bind-stdouterr-to-logger
  "Replaces System.out and System.err with streams that redirect to
  both a Logger and their respective streams with the Levels
  StdOutErrLevel#STDOUT and StdOutErrLevel#STDERR, respectively."
  []
  (Util/logStdOutErr))

(defn severe [s] (.severe logger (str s)))
(defn warning [s] (.warning logger (str s)))
(defn info [s] (.info logger (str s)))
(defn fine [s] (.fine logger (str s)))
(defn finer [s] (.finer logger (str s)))
(defn finest [s] (.finest logger (str s)))